package com.whnk.attendance.controller;

import com.whnk.attendance.api.vo.MonthEmpStatisBatchQueryVo;
import com.whnk.attendance.service.IMonthEmpStatisService;
import com.whnk.attendance.vo.MonthEmpStatisListVo;
import com.whnk.attendance.vo.MonthEmpStatisQueryVo;
import com.whnk.common.core.domain.R;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.page.TableDataInfo;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import com.whnk.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 每月统计（员工口径）Controller
 *
 * @author whnk
 * @date 2021-11-17
 */

@RestController
@RequestMapping("/monthEmpStatis")
@Api(tags = "每月统计（员工口径）表")
public class MonthEmpStatisController extends BaseController
{
    @Autowired
    private IMonthEmpStatisService monthEmpStatisService;

    /**
     * 分页查询每月统计（员工口径）列表
     */
    @PreAuthorize(hasPermi = "attendance:statis:list")
    @GetMapping("/list")
    @ApiOperation(value = "分页查询每月统计（员工口径）列表", notes = "分页查询每月统计（员工口径）列表")
    public TableDataInfo list(@ApiParam(value = "每月统计（员工口径）信息", required = false) MonthEmpStatisQueryVo monthEmpStatisQueryVo)
    {
        startPage();
        List<MonthEmpStatisListVo> list = monthEmpStatisService.queryMonthEmpStatis(monthEmpStatisQueryVo);
        return getDataTable(list);
    }

    /**
     * 导出每月统计（员工口径）列表
     */
    @PreAuthorize(hasPermi = "attendance:statis:export")
    @Log(title = "每月统计（员工口径）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出每月统计（员工口径）列表", notes = "导出每月统计（员工口径）列表")
    public void export(HttpServletResponse response, @ApiParam(value = "每月统计（员工口径）信息", required = false) MonthEmpStatisQueryVo monthEmpStatisQueryVo) throws IOException
    {
        List<MonthEmpStatisListVo> list = monthEmpStatisService.queryMonthEmpStatis(monthEmpStatisQueryVo);
        ExcelUtil<MonthEmpStatisListVo> util = new ExcelUtil<MonthEmpStatisListVo>(MonthEmpStatisListVo.class);
        util.exportExcel(response, list, "每月统计（员工口径）");
    }


    @PostMapping("/batchComputer")
    @ApiOperation(value = "批处理每月统计（员工口径）", notes = "批处理每月统计（员工口径）")
    public R<Boolean> batchComputer(@Validated @RequestBody MonthEmpStatisBatchQueryVo monthEmpStatisBatchQueryVo)
    {
        monthEmpStatisService.batchComputer(monthEmpStatisBatchQueryVo);
        return R.ok(Boolean.TRUE);
    }


}
